<template>
    <a-modal :title="objRecord.name+' 管理员设置'" :width="600" :destroyOnClose="true" :maskClosable="false"
             :visible="visible" @cancel="handleCancel" :footer="false"
    >
        <StaffOneSearch @chooseCallBack="getChooseResult">
            <a slot="chooseTxt">设为管理员</a>
        </StaffOneSearch>
    </a-modal>
</template>
<script>
    import {setWayMaster} from '../public/http.js';
    export default {
        props: ["objRecord"],
        components: {
            //人员单选控件
            StaffOneSearch: () => import('../../hrms/component/StaffOneSearch')
        },
        data() {
            return {
                visible: true, //modal 显示状态,
            };
        },
        methods: {
            //关闭弹窗
            handleCancel() {
                this.visible = false;
                this.$emit('closeModal', {
                    render: false
                });
            },
            //设置门禁管理员
            saveMaster(staffCode, clientMac) {
                let dataObj = {staffCode: staffCode, clientMac: clientMac};
                setWayMaster(dataObj).then(res => {
                    if (res.code === 0) {
                        //成功提醒
                        this.$notification.success({
                            message: '操作成功',
                            description: res.message
                        });
                        this.visible = false;
                        this.$emit('closeModal', {
                            render: true
                        });
                    } else {
                        //错误提醒
                        this.$notification.error({
                            message: '操作失败',
                            description: res.message
                        });
                    }
                    this.loading = false;
                })
            },
            //人员单选控件回调
            getChooseResult(obj) {
                const _that = this;
                const clientMac = this.objRecord.clientMac;
                this.$confirm({
                    width: 500,
                    title: '确定要将 ' + obj.name + ' 设置为门禁管理员吗',
                    content: `设置为门禁管理员后,${obj.name} 将一直拥有当前门禁的通行权限`,
                    okType: 'danger',
                    onOk() {
                        _that.saveMaster(obj.code, clientMac);
                    },
                });
            }
        },
    };
</script>